/*
==================================================================
* 版权所有 © 2025 CaryXiong
* Copyright (C) 2025 CaryXiong(a1816101108@outlook.com)
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
===================================================================
*/




#include<iostream>
using namespace std;

const int MaxSize = 6;

template<class DataType>
class SeqQueue{
    public:
        SeqQueue();
        SeqQueue(DataType a[], int n);
        void EnQueue(DataType x);
        DataType DeQueue();
        DataType GetHead();
        bool Empty();

        void PrintQueue();
        void PrintData();
    private:
        DataType data[MaxSize] = {0};
        int front, rear;
};



template<class DataType>
SeqQueue<DataType> :: SeqQueue(){
    front = rear = MaxSize-1;
}

template<class DataType>
SeqQueue<DataType> :: SeqQueue(DataType a[], int n){
    front = rear = 0;
    for(int i=0; i<n; i++){
        data[i+1] = a[i];
        rear ++;
    }
}

template<class DataType>
void SeqQueue<DataType> :: EnQueue(DataType x){
    if((rear+1)%MaxSize == front) throw "队满";
    rear = (rear+1)%MaxSize;
    data[rear] = x;
}

template<class DataType>
DataType SeqQueue<DataType> :: DeQueue(){
    if(rear == front) throw "队空，无法出队";
    front = (front+1)%MaxSize;
    return data[front];
}

template<class DataType>
DataType SeqQueue<DataType> :: GetHead(){
    if(rear == front) throw "队空，无法获取元素值";
    return data[(front+1)%MaxSize];
}

template<class DataType>
bool SeqQueue<DataType> :: Empty(){
    if(rear == front) return true;
    else return false;
}

template<class DataType>
void SeqQueue<DataType> :: PrintQueue(){
    for(int i=front+1; ; i++){
        cout << data[i%MaxSize] << '\t';
        if(i%MaxSize == rear){
            cout << endl;
            break;
        }
    }
}

template<class DataType>
void SeqQueue<DataType> :: PrintData(){
    for(int i=0; i<MaxSize; i++){
        cout << data[i] << '\t';
    }
    cout << endl;
}

int main(){
    cout << "当前循环队列最多可容纳元素个数：" << MaxSize-1 << endl;
    int a[5] = {1,2,3,4,5};
    SeqQueue<int> Q(a,5);
    
    cout << "当前循环队列为：";
    Q.PrintQueue();

    cout << "取出队首元素：" << Q.DeQueue();
    cout << "当前循环队列为：";
    Q.PrintQueue();

    cout << "将元素10入队，当前循环队列为：";
    Q.EnQueue(10);
    Q.PrintQueue();
    cout << "当前数据表的实际存储内容顺序为：";
    Q.PrintData();

    cout << "取出队首元素：" << Q.DeQueue();
    cout << "当前循环队列为：";
    Q.PrintQueue();

    cout << "将元素100入队，当前循环队列为：";
    Q.EnQueue(100);
    Q.PrintQueue();
    cout << "当前数据表在内存中的存储顺序为：";
    Q.PrintData();

    int test;
    cin >> test;
}